package com.patrol.logisticsmanage.ui.base;

import android.app.Dialog;
import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.RatingBar;
import android.widget.TextView;

import com.patrol.logisticsmanage.R;
import com.patrol.logisticsmanage.ui.canteen.utils.ToastUtils;

import java.util.List;

public class DialogHelper {

    public static void showEditDialog(final Context activity,String content,final DialogListenerContent sureListener) {
        final Dialog dialog = new Dialog(activity, R.style.MyDialog);
        dialog.setContentView(R.layout.dialog_input_reason);
        dialog.setCanceledOnTouchOutside(true);
        EditText et_input_reason = dialog.findViewById(R.id.et_input_reason);
        et_input_reason.setHint(content);
        TextView btn_sure = dialog.findViewById(R.id.btn_sure);
        btn_sure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null != sureListener) {
                    if (!TextUtils.isEmpty(et_input_reason.getText().toString().trim())) {
                        sureListener.handleMessage(et_input_reason.getText().toString().trim());
                        dialog.dismiss();
                    }else {
                        ToastUtils.centerToastWhite(activity,"原因不能为空");
                    }
                }
            }
        });
        dialog.findViewById(R.id.btn_cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
        dialog.findViewById(R.id.layout_pop).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                dialog.dismiss();
            }
        });
        dialog.show();
    }

    public static void showRatingDialog(final Context activity,String content,final DialogListenerContent sureListener) {
        final Dialog dialog = new Dialog(activity, R.style.MyDialog);
        dialog.setContentView(R.layout.dialog_rating_input);
        dialog.setCanceledOnTouchOutside(false);
        EditText et_input_reason = dialog.findViewById(R.id.et_input_reason);
        RatingBar ratingBar = dialog.findViewById(R.id.rb_pingf);
        et_input_reason.setHint(content);
        TextView btn_sure = dialog.findViewById(R.id.btn_sure);
        btn_sure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null != sureListener) {
                    if (!TextUtils.isEmpty(et_input_reason.getText().toString().trim())) {

                    }else {
                        et_input_reason.setText("");
                    }
                    sureListener.handleMessage(((Float)ratingBar.getRating()).intValue() + "", et_input_reason.getText().toString().trim());
                    dialog.dismiss();
                }
            }
        });
        dialog.findViewById(R.id.btn_cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
        dialog.findViewById(R.id.layout_pop).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                dialog.dismiss();
            }
        });
        dialog.show();
    }

    public static void showTwoChoiceDialog(final Context activity, String title, String content,
                                             String cancelText, String sureText, final DialogListenerEmpty cancelListener, final DialogListenerEmpty sureListener) {
        final Dialog dialog = new Dialog(activity, R.style.MyDialog);
        dialog.setContentView(R.layout.dialog_two_choice);
        dialog.setCanceledOnTouchOutside(true);
        TextView tv_title = dialog.findViewById(R.id.tv_title);
        TextView tv_content = dialog.findViewById(R.id.tv_content);
        TextView btn_cancel = dialog.findViewById(R.id.btn_cancel);
        TextView btn_sure = dialog.findViewById(R.id.btn_sure);
        tv_title.setText(title);
        tv_content.setText(content);
        btn_cancel.setText(cancelText);
        btn_sure.setText(sureText);
        btn_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                if (null != cancelListener) {
                    cancelListener.handleMessage();
                }
            }
        });
        btn_sure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                if (null != sureListener) {
                    sureListener.handleMessage();
                }
            }
        });
        dialog.findViewById(R.id.layout_pop).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                dialog.dismiss();
            }
        });
        dialog.show();
    }

    public interface DialogListenerEmpty {
        void handleMessage();
    }

    public interface DialogListenerContent {
        void handleMessage(String... content);
    }

    public interface DialogListener {
        void handleMessage(List<Integer> strings);
        void handleMessage(int choose);
        //  public void handleMessages(String content);
    }
}
